<?php
/**
 * Created by PhpStorm.
 * User: 张辉
 * Date: 2018/8/6
 * Time: 12:58
 */

/*
 * 微信重复推送限制
 */
namespace app\common\redis;
class WeChatPushArticleRepeatRedis extends RedisModel
{
    /**
     * Redis配置名称
     * @var string
     */
    public $redis = 'default';

    /**
     * Redis key
     * @var string
     */
    public $key = 'str:we_chat_push_article_repeat';

    public $setWeChatCoinChoiceKey = 'str:set_WeChat_coin_choice_by_';

    public function setRepeatStr( $open_id, $article_id )
    {
        $this->Set( 1,$this->key.'_'.$open_id.$article_id, 180 );
    }

    public function getRepeatStr(  $open_id, $article_id )
    {
        return $this->Get( $this->key.'_'.$open_id.$article_id );
    }

    public function getRedisKey ( $open_id, $article_id )
    {
        return $this->key.'_'.$open_id."_".$article_id ;
    }

    /**
     * 设置用户微信服务号操作缓存
     * @param $user_id
     * @param $coin_id
     * @param bool $is_follow
     */
    public function setWeChatCoinChoice( $user_id , $number, $coin_id, $is_follow = 1 )
    {
        $body = array(
            'coin_id' => $coin_id,
            'is_follow' => $is_follow
        );

        $body = json_encode( $body );

        $this->Set( $body,$this->setWeChatCoinChoiceKey.$user_id.'_'.$number, 120 );
    }

    public function getWeChatCoinChoice( $user_id, $number )
    {
        $info = $this->Get( $this->setWeChatCoinChoiceKey.$user_id.'_'.$number );
        return $info ? $info : array();
    }














}